package com.sgq.vue.controller.resource;


import com.sgq.vue.entity.resource.JsonMapWeather;
import com.sgq.vue.result.Result;
import com.sgq.vue.service.resource.JsonMapWeatherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author: 83778
 * @date: 2023-12-27 19:25
 * @desc:
 */
@RestController
@RequestMapping("/api/resource/json")
public class JsonMapWeatherController {

    @Autowired
    private JsonMapWeatherService jsonMapWeatherService;

    @GetMapping("/getAllFields")
    public Result getAllFields() {
        List<String> Fields = jsonMapWeatherService.getAllFields();
        return Result.ok(Fields);
    }
    @PostMapping("/addMapping")
    public Result addMapping(@RequestBody JsonMapWeather jsonMapWeather){
        boolean save = jsonMapWeatherService.save(jsonMapWeather);
        return Result.ok(save);
    }

    @PutMapping("/editMapping")
    public Result editMapping(@RequestBody JsonMapWeather jsonMapWeather){
        boolean save = jsonMapWeatherService.updateById(jsonMapWeather);
        return Result.ok(save);
    }

    @DeleteMapping ("/removeMapping/{id}")
    public Result removeMapping(@PathVariable Long id){
        boolean save = jsonMapWeatherService.removeById(id);
        return Result.ok(save);
    }

    @GetMapping  ("/list")
    public Result list(@PathVariable Long id){
        List<JsonMapWeather> list = jsonMapWeatherService.list();
        return Result.ok(list);
    }

    @ApiOperation("获取API获取的json与Weather的映射关系")
    @GetMapping  ("/findMapping/{weatherApiId}")
    public Result findMappingByWeatherApiId(@PathVariable Long weatherApiId){
        JsonMapWeather jsonMapWeather = jsonMapWeatherService.findMappingByWeatherApiId(weatherApiId);
        return Result.ok(jsonMapWeather);
    }

}
